package service

import (
	dom "a-common/domain"
	"a-common/utils/excel"
	"a-demo/dao"
	"a-demo/domain/entity"
	"sync"

	"github.com/xuri/excelize/v2"
)

var (
	senRoomServiceTemp *SenRoomService
	senRoomDao         = dao.NewSenRoomDao()
	senRoomServiceOnce sync.Once
)

type SenRoomService struct{}

func NewSenRoomService() *SenRoomService {
	senRoomServiceOnce.Do(func() {
		senRoomServiceTemp = &SenRoomService{}
	})
	return senRoomServiceTemp
}

// List 分页
func (m *SenRoomService) List(args *entity.SenRoomDto) (dom.PageVo, error) {
	return senRoomDao.List(args, false)
}

// Get 查
func (m *SenRoomService) Get(id string) (entity.SenRoomVo, error) {
	return senRoomDao.Get(id)
}

// Del 删
func (m *SenRoomService) Del(ids string) (int64, error) {
	return senRoomDao.Del(ids)
}

// Add 增
func (m *SenRoomService) Add(args *entity.SenRoomDto) (int64, error) {
	return senRoomDao.Add(args)
}

// Edit 改
func (m *SenRoomService) Edit(args *entity.SenRoomDto) (int64, error) {
	return senRoomDao.Edit(args)
}

// Export 导出
func (m *SenRoomService) Export(args *entity.SenRoomDto, title string) (*excelize.File, error) {
	pageVo, err := senRoomDao.List(args, true)
	if err != nil {
		return nil, err
	}
	return excel.NormalDynamicExport(pageVo.Rows, "Sheet1", title, "", true, false, map[string]string{})
}
